import { _decorator } from 'cc';
import { SpiderSolitaire_GameStorage } from './SpiderSolitaire_GameStorage';
import SpiderSolitaire_GamePanel from './SpiderSolitaire_GamePanel';

export class SpiderSolitaire_GameData {
    //    // static W: number = SpiderSolitaire_GameData.size * SpiderSolitaire_GameData.col;
    //    // static H: number = SpiderSolitaire_GameData.size * SpiderSolitaire_GameData.row;
    static W: number = 700;
    static H: number = 720;
    static row: number = 13; // 行数
    static col: number = 10; // 列数
    static size: number = 64; // SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸
    static w: number = 70; // SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸
    static h: number = 70 * 1.44; // SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸

    //    // static arrGrids: any[][] = [];
    static arrGrids = [];
    static arrBlocks = [];
    static arrCards = [];
    static Game_mode = `mode_3x3`;
    static Score: number = 0;
    static IsMouseDown: boolean = false;
    static 本次滑动是否有合并: boolean = false;
    static colors = [
        { id: 2, color: "#FFF3E7", Label_color: "#424952" },
        { id: 4, color: "#FFEBCE", Label_color: "#424952" },
        { id: 8, color: "#FFC773", Label_color: "#424952" },
        { id: 16, color: "#FFA663", Label_color: "#FFFFFF" },
        { id: 32, color: "#FF8652", Label_color: "#FFFFFF" },
        { id: 64, color: "#FF5D52", Label_color: "#FFFFFF" },
        { id: 128, color: "#C6CB7B", Label_color: "#FFFFFF" },
        { id: 256, color: "#94CF94", Label_color: "#313031" },
        { id: 512, color: "#5ACFAD", Label_color: "#313031" },
        { id: 1024, color: "#52B6CF", Label_color: "#313031" },
        { id: 2048, color: "#528BCF", Label_color: "#FFFFFF" },
        { id: 4096, color: "#7B7BCB", Label_color: "#FFFFFF" },
        { id: 8192, color: "#9D5ACF", Label_color: "#FFFFFF" },
        { id: 16384, color: "#CF5AA7", Label_color: "#FFFFFF" },
        { id: 32768, color: "#CF5A84", Label_color: "#FFFFFF" },
        { id: 65536, color: "#CF406A", Label_color: "#FFFFFF" },
        { id: 131072, color: "#AF2E5A", Label_color: "#FFFFFF" },
        { id: 262144, color: "#8B1A4A", Label_color: "#FFFFFF" },       // 深酒红
        { id: 524288, color: "#F0D7E7", Label_color: "#313031" },       // 浅粉白（交替1）
        { id: 1048576, color: "#6C123B", Label_color: "#FFFFFF" },      // 更深酒红
        { id: 2097152, color: "#E4E1F8", Label_color: "#313031" },      // 浅紫灰（交替2）
        { id: 4194304, color: "#52102F", Label_color: "#FFFFFF" },      // 黑红紫
        { id: 8388608, color: "#F4F4F4", Label_color: "#313031" },      // 银灰白（交替3）
        { id: 16777216, color: "#290918", Label_color: "#FFFFFF" },     // 黑红
        { id: 33554432, color: "#EDE8F6", Label_color: "#313031" },     // 浅紫白（交替4）
        //        // { id: 262144, color: "#8B1A4A", Label_color: "#FFFFFF" },
        //        // { id: 524288, color: "#6C123B", Label_color: "#FFFFFF" },
        //        // { id: 1048576, color: "#52102F", Label_color: "#FFFFFF" },
        //        // { id: 2097152, color: "#3A0C22", Label_color: "#FFFFFF" },
        //        // { id: 4194304, color: "#290918", Label_color: "#FFFFFF" },
        //        // { id: 8388608, color: "#190610", Label_color: "#FFFFFF" },
        //        // { id: 16777216, color: "#0D0308", Label_color: "#FFFFFF" },
        //        // { id: 33554432, color: "#050204", Label_color: "#FFFFFF" },
    ];
    static isSlide: boolean = true;
    static direction;
    static gameState;
    static move_duration = 0.15;
    static InitData() {
        SpiderSolitaire_GameData.arrGrids = [];
        SpiderSolitaire_GameData.arrBlocks = [];

        SpiderSolitaire_GameData.Score = SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].score;
        console.log(`SpiderSolitaire_GameData.Score`, SpiderSolitaire_GameData.Score)

        if (SpiderSolitaire_GameData.Game_mode === `mode_3x3`) {
            SpiderSolitaire_GameData.row = 3;
            SpiderSolitaire_GameData.col = 3;
            // SpiderSolitaire_GameData.size = SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸
        }
        else if (SpiderSolitaire_GameData.Game_mode === `mode_4x4`) {
            SpiderSolitaire_GameData.row = 4;
            SpiderSolitaire_GameData.col = 4;
            // SpiderSolitaire_GameData.size = SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸
        }
        else if (SpiderSolitaire_GameData.Game_mode === `mode_5x5`) {
            SpiderSolitaire_GameData.row = 5;
            SpiderSolitaire_GameData.col = 5;
            // SpiderSolitaire_GameData.size = SpiderSolitaire_GameData.W / SpiderSolitaire_GameData.row; // 方块的尺寸
        }
    }
    // static GetDataMap() {
    //     if (SpiderSolitaire_GameData.Game_mode === `mode_3x3`) {
    //     }
    //     else if (SpiderSolitaire_GameData.Game_mode === `mode_3x3`) {
    //     }
    //     else if (SpiderSolitaire_GameData.Game_mode === `mode_3x3`) {
    //     }
    // }
    static ClearData() {
        SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].score = 0;
        SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].map = [];
        SpiderSolitaire_GameStorage.saveData();

        // SpiderSolitaire_GameData.Score = 0;
        // SpiderSolitaire_GameData.arrGrids = [];
        // SpiderSolitaire_GameData.arrBlocks = [];
    }
    static GetScore() {
        return SpiderSolitaire_GameData.Score;
    }
    static SetScore(_score) {
        SpiderSolitaire_GameData.Score = _score;
        SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].score = _score;
        SpiderSolitaire_GameStorage.saveData();
    }
    static Add_score(_score) {
        let new_score = SpiderSolitaire_GameData.GetScore() + _score;
        SpiderSolitaire_GameData.Update_score(new_score);
    }
    static Update_score(_score) {
        SpiderSolitaire_GameData.SetScore(_score);

        // SpiderSolitaire_GameData.Score = _score;

        if (SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].high_score <= SpiderSolitaire_GameData.Score) {
            SpiderSolitaire_GameStorage.data[SpiderSolitaire_GameData.Game_mode].high_score = SpiderSolitaire_GameData.Score;
            SpiderSolitaire_GameStorage.saveData();
        }

        SpiderSolitaire_GamePanel.Instance.Refresh_score();
    }
}

window["SpiderSolitaire_GameData"] = SpiderSolitaire_GameData;